package com.HospitalOutpatient.controller;

import com.HospitalOutpatient.annotation.LoginToken;
import com.HospitalOutpatient.entity.Doctor;
import com.HospitalOutpatient.entity.User;
import com.HospitalOutpatient.service.DoctorService;
import com.HospitalOutpatient.vo.DoctorAndOutpatientAndUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private DoctorService doctorService;
    @LoginToken
    @PostMapping("/getAllDoctorByName")
    public Result getAllDoctorByName(@RequestBody Doctor doctor){
        List<DoctorAndOutpatientAndUser> doctorList = doctorService.getAllDoctorByName(doctor.getDoctorName());
        return new Result(Code.GET_OK,doctorList,"医生信息");
    }
    @LoginToken
    @PostMapping("/editDoctor")
    public Result editDoctor(@RequestBody DoctorAndOutpatientAndUser doctor){
        boolean b = doctorService.editDoctor(doctor);
        if(b == false){
            return new Result(Code.UPDATE_ERR,null,"更新医生信息失败");
        }
        return new Result(Code.UPDATE_OK,null,"更新医生信息成功");
    }
    @LoginToken
    @PostMapping("/deleteDoctor")
    public Result deleteDoctor(@RequestBody DoctorAndOutpatientAndUser doctor){
        boolean b = doctorService.deleteDoctor(doctor);
        if(b == false){
            return new Result(Code.DELETE_ERR,null,"删除失败");
        }
        return new Result(Code.DELETE_OK,null,"删除成功");
    }
    @LoginToken
    @PostMapping("/addDoctor")
    public Result addDoctor(@RequestBody DoctorAndOutpatientAndUser doctor){

        System.out.println(doctor);
        boolean b = doctorService.addDoctor(doctor);
        if(b == false){
            return new Result(Code.SAVE_ERR,null,"非法信息或用户名重复");
        }
        return new Result(Code.SAVE_OK,null,"添加医生信息成功");
    }
}
